package com.pro.common.service.file.controller;

import com.pro.common.api.model.ILoginInfo;
import com.pro.common.api.user.file.model.db.UserUploadRecord;
import com.pro.common.service.file.model.dto.FileUploadDTO;
import com.pro.common.service.file.model.request.FileUploadBatchRequest;
import com.pro.common.service.file.model.request.FileUploadTempBatchRequest;
import com.pro.common.service.file.model.request.UserUploadRecordRequest;
import com.pro.common.service.file.service.unit.UserFileStorageUnitService;
import com.pro.framework.api.file.storage.PresignedUrlResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文件上传控制器
 */
@Slf4j
@RestController
@RequestMapping("")
@AllArgsConstructor
public class FileStorageController {

    private final UserFileStorageUnitService fileStorageUnitService;

    /**
     * 批量生成预签名上传 URL
     */
    @Operation(summary = "预签名上传")
    @PostMapping("/user/fileStorage/presigned/upload/batch")
    public List<PresignedUrlResponse> generateBatchPresignedUploadUrls(
            @Parameter(hidden = true) ILoginInfo loginInfo,
            @RequestBody FileUploadBatchRequest request
    ) {
        FileUploadDTO common = request.getCommon();
        common.setUserId(loginInfo.getId());
        if (common.getParentId() == null) {
            common.setParentId(0L);
        }
        return fileStorageUnitService.generateBatchPresignedUploadUrls(loginInfo, request);
    }

    /**
     * 批量生成预签名上传 URL
     */
    @Operation(summary = "预签名上传")
    @PostMapping("/user/fileStorage/generatePresignedUploadUrls/{business}")
    public List<UserUploadRecord> generatePresignedUploadUrls(
            @PathVariable("business") String business,
            @Parameter(hidden = true) ILoginInfo loginInfo,
            @RequestBody UserUploadRecordRequest request
    ) {
        return fileStorageUnitService.generatePresignedUploadUrls(loginInfo.getId(), request, business);
    }


}
